package com.wkk.authentication.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wkk.authentication.dto.UserLoginDto;
import com.wkk.authentication.entity.UmsUser;
import com.wkk.authentication.mapper.UmsUserMapper;
import com.wkk.authentication.service.UmsUserService;
import com.wkk.utils.NoBugTools;
import com.wkk.utils.PasswordUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author : WangKeKe
 * @date : 2020/9/12 9:47
 * Description :
 */


@Service
@Slf4j
public class UmsUserServiceImpl extends ServiceImpl<UmsUserMapper, UmsUser> implements UmsUserService {

    @Override
    public Boolean accountRegister(UserLoginDto userLoginDto) {
        // 获取MD5加密的盐值
        String randomSalt = PasswordUtil.getRandomSalt();
        // 密码加密
        String md5Password = PasswordUtil.encrypt(userLoginDto.getUsername(), userLoginDto.getPassword(), randomSalt);
        // 数据持久化
        UmsUser umsUser = new UmsUser()
                .setUsername(userLoginDto.getUsername())
                .setPassword(md5Password)
                .setSalt(randomSalt);
        baseMapper.insert(umsUser);
        // 通过MP的插入回显 - 来判断用户是否注册成功
        log.info("用户注册接口实现插入 >>>>>>用户ID：" + umsUser.getId());
        return NoBugTools.isNotEmpty(umsUser.getId());
    }
}
